import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../../routers/application.dart';

class HotZone extends StatelessWidget {
  final List hotGoodsList;
  const HotZone({Key key, this.hotGoodsList}) : super(key: key);

  Widget _buildTitle() {
    return Container(
      alignment: Alignment.center,
      margin: EdgeInsets.only(top: 10.0),
      padding: EdgeInsets.all(5.0),
      decoration: BoxDecoration(
          color: Colors.white,
          border:
              Border(bottom: BorderSide(width: 0.5, color: Colors.black12))),
      child: Text('火爆专区'),
    );
  }

  Widget _buildList(context) {
    if (hotGoodsList.length != 0) {
      List<Widget> widgetList = hotGoodsList.map((item) {
        return InkWell(
          onTap: () {
            // print('点击了某个火爆商品');
            Application.router
                .navigateTo(context, '/detail?id=${item['goodsId']}');
          },
          child: Container(
            width: ScreenUtil().setWidth(372),
            child: Column(
              children: <Widget>[
                Image.network(item['image']),
                Container(
                  height: ScreenUtil().setHeight(60),
                  color: Colors.white,
                  alignment: Alignment.center,
                  child: Text(item['name'],
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(
                          fontSize: ScreenUtil().setSp(26),
                          color: Colors.pinkAccent)),
                ),
                Container(
                  color: Colors.white,
                  padding: EdgeInsets.all(5),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Text('￥${item['mallPrice']}'),
                      Container(
                        margin: EdgeInsets.only(left: 5.0),
                        child: Text('￥${item['price']}',
                            style: TextStyle(
                                color: Colors.black12,
                                decoration: TextDecoration.lineThrough)),
                      )
                    ],
                  ),
                )
              ],
            ),
          ),
        );
      }).toList();

      return Wrap(
        spacing: 2,
        children: widgetList,
      );
    } else {
      return Text('');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[_buildTitle(), _buildList(context)],
      ),
    );
  }
}
